<?php
namespace Content\Controller;
use Common\Controller\AdminbaseController;
class LeavemsgController extends AdminbaseController 
{   
    protected $leavemsgObj;
	public function _initialize()
	{
        parent::_initialize();
        $this->leavemsgObj = D("Leavemsg");
	}

	public function index()
	{
    	$this->lists();
	}

	public function lists()
	{

      $count      =  $this->leavemsgObj->count();
      $Page       = new \Think\Page($count,15);
      $show       = $Page->show();
      $list = $this->leavemsgObj->order(array("status" => "ASC","id" => "ASC"))->limit($Page->firstRow.','.$Page->listRows)->select();
      $this->assign('list',$list);
      $this->assign('page',$show); 
      $this->display('list');
	}
    public function edit($id=0)
    {
    	$leavemsgObj=null;
    	if ($id>0) 
    	{
            $leavemsgObj=$this->leavemsgObj->find($id);
    	    $this->assign("leavemsg",$leavemsgObj);
        }
    	$this->display("edit");
    }
    public function save()
    {
        $id = I('post.inputId','','htmlspecialchars');
        $callmsg = I('post.inputCallmsg','','htmlspecialchars');
        $status = I('post.inputStatus','','htmlspecialchars');
        $data = array();
        $data['callmsg'] = $callmsg;
        $data['status'] = $status;
        $data['calltime'] = time();
        $data['iscall'] = "Y";
        if($id>0)
        {
            $editResult = $this->leavemsgObj->where("id=%d",$id)->save($data);
            $arr = array("status"=>'1',"message"=>"回复在线留言成功","url"=>"index");
        }
        else
        {
            $arr = array("status"=>'0',"message"=>"回复在线留言失败");
        }
        echo json_encode($arr);
    }
    function check_verify($code, $id = '')
    {    
        $verify = new \Think\Verify();    
        return $verify->check($code, $id);
    }
	/*排序更新*/
    public function listorder()
    {
       $ids = I('post.ids','-1','htmlspecialchars');
       $listorders = I('post.listorders','','htmlspecialchars');  
       parent::_listorder($this->leavemsgObj,$ids,$listorders);
    }
    /*单个删除 id*/
    public function delete($id)
    {
        parent::_delete($this->leavemsgObj,$id);
    }

    /* 批量删除 ids*/
    public function checkDeletes($ids)
    {
        parent::_checkDeletes($this->leavemsgObj,$ids);
    }
    /* 单个修改当前状态status 0 1 -1*/
    public function changeStatus($id,$status)
    {
        parent::_changeStatus($this->leavemsgObj,$id,$status);
    }
    /*批量 修改当前状态status 0 1 -1*/
    public function checkChanges($status,$ids)
    {
        parent::_checkChanges($this->leavemsgObj,$status,$ids);
    }
}
?>